class Solution {
    public int longestSubsequence(int[] arr, int difference) {
        int len = arr.length;
        int ans =0;
        Map<Integer,  Integer> dp = new HashMap<>();
        for(int i =0; i < len; i++){
            int dpI = dp.getOrDefault(arr[i] - difference, 0) + 1;
            dp.put(arr[i], dpI);
            ans = Math.max(ans, dpI);
        }
        return ans;
    }
}